import { app, auth } from "./common";

export async function upload(file, prefix){
  if (!auth.currentUser) {
    console.warn('用户没有登录');
    return
  }
  const cloudPath = prefix || file.name
  return app.uploadFile({
    // 云存储的路径
    cloudPath: cloudPath,
    // 需要上传的文件，File 类型
    filePath: file
  })
}

export async function deleteFile(files=[]) {
  files = [].concat(files)
  return app.deleteFile({
    fileList: files
  })
  .then(res => {
    // handle success
    console.log(res)
  }).catch(error => {
    console.log(error);
    // handle error
  })
}

export async function downloadFile(fileId) {
  return app.downloadFile({
    fileId
  })
  // .then(res => {
  //   // handle success
  //   console.log(res.fileList)
  // }).catch(error => {
  //   // handle error
  // })
}